package vars

import (
	"d-serv-go/server/core/bean"
	"d-serv-go/server/core/consts"
	"d-serv-go/server/core/db"
)

const (
	/** 公共配置字典编码 */
	SY_COMM_CONFIG_PUBLIC = "SY_COMM_CONFIG_PUBLIC"
	/** 私有配置字典编码 */
	SY_COMM_CONFIG = "SY_COMM_CONFIG"
)

var ConfVar = newConfVar()

type confVar struct {
	*bean.Bean
}

func newConfVar() *confVar {
	return &confVar{
		Bean: bean.NewBean(""),
	}
}

func (v *confVar) init() {
	// TODO 从date var的初始化
}
func (v *confVar) GetMap(onlyClient bool) map[string]interface{} {
	//
	confMap := make(map[string]interface{})
	itemMap := db.DictMgr.GetItemMap(db.DictMgr.GetDict(SY_COMM_CONFIG_PUBLIC)) //公有配置
	for _, key := range itemMap.Keys() {
		item := itemMap.GetBean(key)
		if item != nil && (item.GetInt("FLAG") != consts.NO_INT) && !(onlyClient && item.GetInt("CONF_FLAG") != consts.YES_INT) {
			confMap["@C_"+key+"@"] = item.GetStr("NAME")
		}
	}
	itemMap = db.DictMgr.GetItemMap(db.DictMgr.GetDict(SY_COMM_CONFIG)) //私有配置
	for _, key := range itemMap.Keys() {
		item := itemMap.GetBean(key)
		if item != nil && (item.GetInt("FLAG") != consts.NO_INT) && !(onlyClient && item.GetInt("CONF_FLAG") != consts.YES_INT) {
			confMap["@C_"+key+"@"] = item.GetStr("NAME")
		}
	}
	return confMap
}
